package com.yt.base.util;

import javax.servlet.jsp.tagext.TagSupport;

import com.yt.base.model.AclUser;
import com.yt.base.vo.UserMenuVo;

public class PermissionTag extends TagSupport {
	private static final long serialVersionUID = 1L;
	// private Integer modelId;//uid
	private String key;// 2_12_32 categoryId_ privilegeId_operationId
						// 一级菜单Id_二级菜单Id_操作key

	public PermissionTag() {

	}

	@Override
	public int doStartTag() {
		Object obj = pageContext.getSession().getAttribute(Constants.LOGINUSER);
		Object obj2 = pageContext.getSession().getAttribute(Constants.USER_MENU_KEY);
		
		if (obj != null && obj2 != null) {
			AclUser loginBean = (AclUser) obj;
			UserMenuVo menuVo = (UserMenuVo) obj2;
			Object type = pageContext.getRequest().getAttribute("type");
			Object  itemId =pageContext.getRequest().getAttribute("itemId");
			
			if (loginBean != null && menuVo!=null && type!=null && itemId!=null  && menuVo.checkPermission(type.toString() + "_" + itemId.toString() + "_" + key)) {
				return EVAL_PAGE;
			}
		}
		return SKIP_BODY;
	}

	public String getKey() {
		return key;
	}

	public void setKey(String key) {
		this.key = key;
	}
}
